// 创建三个对象，将其分别与指定的html页面元素关联
let usernameInput = document.querySelector("#username");
let passwordInput = document.querySelector("#password");
let submitButton = document.querySelector("#submit");

submitButton.onclick = function() {
    $.ajax({
        // 发送请求
        type: 'post',
        url: '/login',
        data: {
            username: usernameInput.value,
            password: passwordInput.value,
        },

        // 接收响应
        success: function(body) {
            if (body != null && body.userId > 0) {
                location.assign('/hall.html');
            } else {
                alert("登陆失败！");
            }
        },
        error: function() {
            alert("登陆失败！");
        }
    });
}